﻿using System;
using System.Threading;

namespace HslCommunication.LogNet
{
	/// <summary>
	/// 单条日志的记录信息，包含了消息等级，线程号，关键字，文本信息<br />
	/// Record information of a single log, including message level, thread number, keywords, text information
	/// </summary>
	// Token: 0x020000DE RID: 222
	public class HslMessageItem
	{
		/// <summary>
		/// 实例化一个默认的对象<br />
		/// Instantiate a default object
		/// </summary>
		// Token: 0x06001123 RID: 4387 RVA: 0x00062163 File Offset: 0x00060363
		public HslMessageItem()
		{
			this.Id = Interlocked.Increment(ref HslMessageItem.IdNumber);
			this.Time = DateTime.Now;
		}

		/// <summary>
		/// 单个记录信息的标识ID，程序重新运行时清空，代表程序从运行以来的日志计数，不管存储的或是未存储的<br />
		/// The ID of a single record of information. It is cleared when the program is re-run. 
		/// It represents the log count of the program since it was run, whether stored or unstored.
		/// </summary>
		// Token: 0x17000261 RID: 609
		// (get) Token: 0x06001124 RID: 4388 RVA: 0x00062191 File Offset: 0x00060391
		// (set) Token: 0x06001125 RID: 4389 RVA: 0x00062199 File Offset: 0x00060399
		public long Id { get; private set; }

		/// <summary>
		/// 消息的等级，包括DEBUG，INFO，WARN，ERROR，FATAL，NONE共计六个等级<br />
		/// Message levels, including DEBUG, INFO, WARN, ERROR, FATAL, NONE total six levels
		/// </summary>
		// Token: 0x17000262 RID: 610
		// (get) Token: 0x06001126 RID: 4390 RVA: 0x000621A2 File Offset: 0x000603A2
		// (set) Token: 0x06001127 RID: 4391 RVA: 0x000621AA File Offset: 0x000603AA
		public HslMessageDegree Degree { get; set; } = HslMessageDegree.DEBUG;

		/// <summary>
		/// 线程ID，发生异常时的线程号<br />
		/// Thread ID, the thread number when the exception occurred
		/// </summary>
		// Token: 0x17000263 RID: 611
		// (get) Token: 0x06001128 RID: 4392 RVA: 0x000621B3 File Offset: 0x000603B3
		// (set) Token: 0x06001129 RID: 4393 RVA: 0x000621BB File Offset: 0x000603BB
		public int ThreadId { get; set; }

		/// <summary>
		/// 消息文本，记录日志的时候给定<br />
		/// Message text, given when logging
		/// </summary>
		// Token: 0x17000264 RID: 612
		// (get) Token: 0x0600112A RID: 4394 RVA: 0x000621C4 File Offset: 0x000603C4
		// (set) Token: 0x0600112B RID: 4395 RVA: 0x000621CC File Offset: 0x000603CC
		public string Text { get; set; }

		/// <summary>
		/// 记录日志的时间，而非存储日志的时间<br />
		/// The time the log was recorded, not the time it was stored
		/// </summary>
		// Token: 0x17000265 RID: 613
		// (get) Token: 0x0600112C RID: 4396 RVA: 0x000621D5 File Offset: 0x000603D5
		// (set) Token: 0x0600112D RID: 4397 RVA: 0x000621DD File Offset: 0x000603DD
		public DateTime Time { get; set; }

		/// <summary>
		/// 消息的关键字<br />
		/// Keyword of the message
		/// </summary>
		// Token: 0x17000266 RID: 614
		// (get) Token: 0x0600112E RID: 4398 RVA: 0x000621E6 File Offset: 0x000603E6
		// (set) Token: 0x0600112F RID: 4399 RVA: 0x000621EE File Offset: 0x000603EE
		public string KeyWord { get; set; }

		/// <summary>
		/// 是否取消写入到文件中去，在事件 <see cref="E:HslCommunication.LogNet.LogNetBase.BeforeSaveToFile" /> 触发的时候捕获即可设置。<br />
		/// Whether to cancel writing to the file, can be set when the event <see cref="E:HslCommunication.LogNet.LogNetBase.BeforeSaveToFile" /> is triggered.
		/// </summary>
		// Token: 0x17000267 RID: 615
		// (get) Token: 0x06001130 RID: 4400 RVA: 0x000621F7 File Offset: 0x000603F7
		// (set) Token: 0x06001131 RID: 4401 RVA: 0x000621FF File Offset: 0x000603FF
		public bool Cancel { get; set; }

		/// <inheritdoc />
		// Token: 0x06001132 RID: 4402 RVA: 0x00062208 File Offset: 0x00060408
		public override string ToString()
		{
			bool flag = this.Degree != HslMessageDegree.None;
			string result;
			if (flag)
			{
				bool flag2 = string.IsNullOrEmpty(this.KeyWord);
				if (flag2)
				{
					result = string.Format("[{0}] {1:yyyy-MM-dd HH:mm:ss.fff} Thread [{2:D3}] {3}", new object[]
					{
						LogNetManagment.GetDegreeDescription(this.Degree),
						this.Time,
						this.ThreadId,
						this.Text
					});
				}
				else
				{
					result = string.Format("[{0}] {1:yyyy-MM-dd HH:mm:ss.fff} Thread [{2:D3}] {3} : {4}", new object[]
					{
						LogNetManagment.GetDegreeDescription(this.Degree),
						this.Time,
						this.ThreadId,
						this.KeyWord,
						this.Text
					});
				}
			}
			else
			{
				result = this.Text;
			}
			return result;
		}

		/// <summary>
		/// 返回表示当前对象的字符串，剔除了关键字<br />
		/// Returns a string representing the current object, excluding keywords
		/// </summary>
		/// <returns>字符串信息</returns>
		// Token: 0x06001133 RID: 4403 RVA: 0x000622DC File Offset: 0x000604DC
		public string ToStringWithoutKeyword()
		{
			bool flag = this.Degree != HslMessageDegree.None;
			string result;
			if (flag)
			{
				result = string.Format("[{0}] {1:yyyy-MM-dd HH:mm:ss.fff} Thread [{2:D3}] {3}", new object[]
				{
					LogNetManagment.GetDegreeDescription(this.Degree),
					this.Time,
					this.ThreadId,
					this.Text
				});
			}
			else
			{
				result = this.Text;
			}
			return result;
		}

		// Token: 0x04000474 RID: 1140
		private static long IdNumber;
	}
}
